﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 影楼婚纱摄影系统
{
    public partial class update_staff : Form
    {
        public update_staff(string sId, string sPwd, string sName, string position, string workyears)
        {
            InitializeComponent();
            textBox1.Text = sId;
            textBox2.Text = sPwd;
            textBox3.Text = sName;
            textBox4.Text = position;
            textBox5.Text = workyears;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["marry"].ConnectionString;
            //创建SqlConnection的实例
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection(str);
                //打开数据库
                conn.Open();
                string sql = "update staff set sPwd='{0}', sName='{1}',position='{2}',workyears='{3}' where sId='{4}'";
                //填充占位符
                sql = string.Format(sql, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox1.Text);
                //创建SqlCommand类的对象
                SqlCommand cmd = new SqlCommand(sql, conn);
                //执行修改操作的SQL
                cmd.ExecuteNonQuery();
                //弹出成功提示
                MessageBox.Show("修改成功！");
                //设置当前窗体DislogResult结果为OK
                this.DialogResult = DialogResult.OK;
                //关闭窗体
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("修改失败！" + ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    //关闭数据库连接
                    conn.Close();
                }
            }
        }
    }
}
